/**
 * Created by lenovo on 2018/1/8.
 */
define(['ngApp', 'ngHttp', 'jquery', 'ngConstant', 'ngAlert','bootstrap'], function (ngApp, ngHttp, JQ, ngConstant, ngAlert) {
    ngApp.controller("message", function ($scope, $http, $timeout, $rootScope, $state, $uibModal, commonFn, $cookies,$window) {
        // $('#message').height($(window).height());

        function getMsg() {
            $http({
                url: ngConstant.interfaceHost + 'manager/msg/findAllMsgInfo',
                method: 'GET',
                headers: {'Authorization':$cookies.get("token")}
            }).then(function(res){
                console.log(res);
                $scope.msgDetail = res.data.data;
            });
        }
        getMsg();

        function getAll(){
            $http({
                url: ngConstant.interfaceHost + 'manager/msg/findUnreadCount',
                method: 'GET',
                headers: {'Authorization':$cookies.get("token")}
            }).then(function(res){
                $rootScope.msgNum = res.data.data;

            });
        }


        //标记已读接口
        $scope.readClick = function($event) {
            if(this.item.readSign == 1) {
                ngAlert.errorMsg('请不要重复操作');
                return false;
            }
            this.item.readSign = 1;
            var that = this.item;
            $http({
                url: ngConstant.interfaceHost + 'admin/msg/modifyToRead',
                method: 'POST',
                data:{"id":this.item.id},
                headers: {'Authorization':$cookies.get("token")}
            }).then(function(res){
            });
        };

        //删除接口
        $scope.deleteMsg = function(){
            ngAlert.open('确认删除本条记录？');
            var msg = [];
            msg[0] = {};
            msg[0].id = this.item.id;
            $('.layui-layer-btn').click(function(){
                $http({
                    url: ngConstant.interfaceHost + 'manager/msg/deleteMsgInfo',
                    method: 'POST',
                    data:msg,
                    headers: {'Authorization':$cookies.get("token")}
                }).then(function(res){
                    ngAlert.successMsg(res.data.data);
                    getMsg();
                    getAll();
                });
            });
        };



    })
});